home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / TwinOpus2 / REXX / DOpus / ReName.rexx < prev    next >
OS/2 REXX Batch file  |  1994-10-13  |  3KB  |  125 lines

  1. /*
  2.  *
  3.  * Rename file(s) with TwinExpres from DOpus.
  4.  *
  5.  * (c) 1994 by K.P. van Beem (2:280/464.2, patrick.van.beem@aobh.xs4all.nl)
  6.  *
  7.  * Based on the DOpusLhaARexx package by Geoff Seeley (but you can better
  8.  * use GuiArc in stead of DOpus and a script, to deal with archives)
  9.  *
  10.  */
  11.  
  12.  
  13. DOpusPort   = 'DOPUS.1'
  14.  
  15. if ~show(l,"rexxsupport.library") then        
  16.    call addlib("rexxsupport.library",0,-30,0)
  17. if showlist('Ports', DOpusPort) = 0 then do
  18.    say 'Directory Opus Arexx port not found. Aborting.'
  19.    call CleanUp
  20. end
  21.  
  22. address 'DOPUS.1'
  23. options results
  24.  
  25. /* setup DOpus window and tell user what's happening */
  26. Busy on
  27. TopText "Renaming selected files..."
  28.  
  29.  
  30. /* Get the current path and do file rename */
  31. 'Status 6 -1'
  32. GetEntry Result
  33. FilePath = Result
  34. if left(FilePath,1) ~= '*' then do
  35.    TopText "You are not in a 'Twin' directory."
  36.    Busy off
  37.    exit
  38. end
  39.  
  40. FilePath = SubStr(FilePath,2)
  41. GetSelectedAll
  42. SelectedEntries = result
  43. if SelectedEntries = 'RESULT' then do
  44.    TopText "No files selected."
  45.    call CleanUp
  46. end
  47. NumberOfEntries = words(SelectedEntries)
  48. do EntryNumber = 1 to NumberOfEntries
  49.    Index = word(SelectedEntries, EntryNumber)
  50.    GetEntry Index+1
  51.    Entry = result
  52.    File = strip(left(Entry,25))
  53.    getstring '"Rename' File 'as?"' File
  54.    NewFile = Result
  55.    if NewFile="" | rc~=0 then do
  56.       TopText "You have to specify a new name"
  57.       call CleanUp
  58.    end
  59.    if right(FilePath,1) = ':' then do
  60.       File = Quote(FilePath || File)
  61.       NewFile = Quote(FilePath || NewFile)
  62.    end
  63.    else do
  64.       File = Quote(FilePath || '/' || File)
  65.       NewFile = Quote(FilePath || '/' || NewFile)
  66.    end
  67.    address command 'echo >PPipe: rename' File NewFile
  68.    selection = Index||' 0 0'
  69.    SelectEntry selection
  70. end
  71.  
  72. TopText "Ready"
  73. 'DisplayDir -1'
  74. address AREXX "Rexx:DOpus/Reread.rexx"
  75. call CleanUp
  76.  
  77. exit
  78.  
  79. /*---------------------------------------------------------------------------*/
  80.  
  81. CleanUp: /* Remove any files and exit */
  82.    Busy off
  83.    exit
  84. return
  85.  
  86. /*--------------------------------------------------------------------------*/
  87.  
  88. Quote: procedure /* add quotes to string */
  89.    parse arg string
  90. return '"'||string||'"'
  91.  
  92. /*--------------------------------------------------------------------------*/
  93.  
  94. GetWord: procedure /* get word from '|' separated string */
  95.  
  96.   parse arg number,words
  97.  
  98.   if(left(words,1) ~= '|') then
  99.      words = '|'||words
  100.   do i=1 to number
  101.      idx = index(words, '|');
  102.      words = substr(words, idx+1)
  103.   end
  104.   end = index(words, '|') - 1
  105.   if words = "" then
  106.      return ""
  107.   ret_str = substr(words, 1, end)
  108. return ret_str
  109.  
  110. /*--------------------------------------------------------------------------*/
  111.  
  112. CountWords: procedure /* count words from '|' separated string */
  113.  
  114.    parse arg words
  115.  
  116.    count = 0
  117.    idx = index(words, '|')
  118.    do while idx ~= 0
  119.      count = count + 1
  120.      words = substr(words, idx+1)
  121.      idx = index(words, '|')
  122.    end
  123. return count
  124.  
  125.